package com.wxm.killing.mq.service;

import com.wxm.killing.mq.dao.TbContractDao;
import com.wxm.killing.mq.dao.TbSysConfigDao;
import com.wxm.killing.mq.dao.TbUserDao;
import com.wxm.killing.mq.entity.TbContract;
import com.wxm.killing.mq.entity.TbSysConfig;
import com.wxm.killing.mq.entity.TbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description 几个常用的缓存
 * @author: wxm
 * @date: 2019/12/6 22:21
 * @version: 1.0
 */
@Component
public class CommonCacheService {

    @Autowired
    private TbUserDao tbUserDao;

    @Autowired
    private TbSysConfigDao tbSysConfigDao;

    @Autowired
    private TbContractDao tbContractDao;

    @Cacheable(value="CommonCache")
    public TbUser getUserByToken(String token){
        TbUser tbUserParam = new TbUser();
        tbUserParam.setToken(token);
        return tbUserDao.selectOne(tbUserParam);
    }

    @Cacheable(value="CommonCache")
    public TbUser getUserById(Integer id){
        return tbUserDao.selectByPrimaryKey(id);
    }

    @Cacheable(value="CommonCache")
    public List<TbSysConfig> getConfigAll(){
        return tbSysConfigDao.selectAll();
    }

    @Cacheable(value="CommonCache")
    public TbContract getBycontractId(Integer contractId){
        return tbContractDao.selectByPrimaryKey(contractId);
    }
}
